#include "gtest/gtest.h"

#include "Persistence.h"

using namespace leveldb;

TEST(KeyValueParserTest, test){
	std::string s = {0x01, 0x05, 0x68, 0x65, 0x6C, 0x6C, 0x6F, };
	{
		KeyValueParser kvp(s);
		uint64_t key = 0;
		ASSERT_TRUE(kvp.key(&key));
		ASSERT_EQ(1ull, key);
		Slice result;
		ASSERT_TRUE(kvp.value(&result));
		ASSERT_EQ("hello", result);
	}
	{
		KeyValueParser kvp(s);
		uint64_t key = 0;
		Slice result;
		ASSERT_TRUE(kvp.keyValue(&key, &result));
		ASSERT_EQ(1ull, key);
		ASSERT_EQ("hello", result);
	}
}

TEST(KeyValueBuilderTest, testMain){
    KeyValueBuilder kvp;
    kvp.put(1, "hello");
    ASSERT_EQ(7ull, kvp.approximateSize());

    std::string expectBytes = "0x01 0x05 0x68 0x65 0x6C 0x6C 0x6F ";
    ASSERT_EQ(expectBytes, kvp.toString());
}
